Skip to content

Strip control characters from contract read output - #2672

Merged
fnando merged 1 commit into
mainfrom
sanitize-contract-read-output
Aug 10, 2026
Merged

Strip control characters from contract read output#2672
fnando merged 1 commit into
mainfrom
sanitize-contract-read-output

Conversation

@fnando

@fnando fnando commented Aug 6, 2026

Copy link
Copy Markdown
Member

What

Sanitizes the key/value fields in stellar contract read's default (--output string) output so control and escape sequences can no longer reach the terminal unescaped. The per-entry record building is extracted into a small entry_record helper and the String branch now wraps soroban_spec_tools::to_string with soroban_spec_tools::sanitize. A regression test covers a top-level ScVal::Symbol carrying escape bytes.

Why

soroban_spec_tools::to_string returns raw, unescaped bytes for a top-level ScVal::Symbol, and the default output writes those straight to the terminal via the CSV writer. Every other output mode (JSON/XDR) already escapes its content, and the auth-entry signing prompt was hardened the same way in #2667. This applies the same defense-in-depth to the contract read display path so untrusted ledger content cannot smuggle terminal escape sequences into a user's terminal.

Known limitations

N/A

Copilot AI balanced review requested due to automatic review settings August 6, 2026 14:45
@github-project-automation github-project-automation Bot moved this to Backlog (Not Ready) in DevX Aug 6, 2026
@fnando fnando self-assigned this Aug 6, 2026
@fnando fnando moved this from Backlog (Not Ready) to Needs Review in DevX Aug 6, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Sanitizes contract read string output to prevent terminal control-sequence injection.

Changes:

  • Extracts ledger-entry formatting into entry_record.
  • Sanitizes string-formatted keys and values.
  • Adds a unit regression test for malicious symbols.

Comment thread cmd/soroban-cli/src/commands/contract/read.rs
@fnando
fnando force-pushed the sanitize-contract-read-output branch from f69f615 to 6e9435d Compare August 10, 2026 18:03
@fnando
fnando merged commit b8ef49e into main Aug 10, 2026
229 checks passed
@fnando
fnando deleted the sanitize-contract-read-output branch August 10, 2026 20:41
@github-project-automation github-project-automation Bot moved this from Needs Review to Done in DevX Aug 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants